//
//  ZDDismissAnimation.swift
//  1026SwiftSinaWeiBo
//
//  Created by Apple on 15/11/9.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class ZDDismissAnimation: NSObject, UIViewControllerAnimatedTransitioning {
    
    ///返回动画时间
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        
        return 0.25
    }
    
    ///动画
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        
        //取到当前modal出控制器的view
        let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
        
        UIView.animateWithDuration(transitionDuration(nil), delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            
            //y方向缩放系数不能直接设置为0  否则直接消失 看不到动画效果
            fromView?.transform = CGAffineTransformMakeScale(1.0, 0.01)
            
            }) { (_) -> Void in
                
                transitionContext.completeTransition(true)
        }
    }

}
